package com.zhou.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.bpm.entity.BpmNode;
import com.zhou.bpm.entity.BpmProcess;
import com.zhou.bpm.service.IBpmNodeService;
import com.zhou.bpm.service.IBpmProcessService;
import com.zhou.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zhou.bpm.enmu.NodeApproveType.PARALLEL_APPROVAL;
import static com.zhou.common.Constants.APPLY;

/**
 * @Author: zhoujinchuan
 * @Description: TODO (bpm_process控制器)
 * @Date: 2023-10-25 11:10:39
 */
@Slf4j
@RestController
@Api(tags = "流程")
@RequestMapping("/bpmProcess")
public class BpmProcessController {

    @Autowired
    private IBpmProcessService bpmProcessService;

    @PostMapping
    @ApiOperation("新增或编辑流程")
    public Result saveOrUpdate(@RequestBody BpmProcess bpmProcess){
        bpmProcessService.saveOrUpdatePlus(bpmProcess);
        return Result.ok();
    }

    @ApiOperation("删除流程")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id){
        bpmProcessService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("查询流程详情")
    @GetMapping("/{id}")
    public Result<BpmProcess> find(@PathVariable("id") Long id){
        BpmProcess process = bpmProcessService.getById(id);
        return Result.success(process);
    }

    @ApiOperation("分页查询流程列表")
    @GetMapping("/pageList")
    public Result<Page<BpmProcess>> list(@RequestParam(required = false, defaultValue = "0") int pageNum,
                  @RequestParam(required = false, defaultValue = "10") int pageSize) {
        Page<BpmProcess> page = bpmProcessService.page(new Page<>(pageNum, pageSize));
        return Result.success(page);
    }

}
